<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css" />
    <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.css" />
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=G3GKeZsowwfaOlY71VAd0TfR"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.js"></script>

    <style>
        .layui-input-inline,.buttondiv .layui-input-inline {
            float: left;
            width: 300px !important;
            margin-right: 10px;
        }
        .error{
            color: red;
            line-height: 20px;
        }
        .layui-form-item {
            margin-bottom: 7px !important;
            clear: both;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" lay-filter="formTest" id="formTest">
            <div class="layui-form-item ">
                <label class="layui-form-label" for="name"><span style="color: red;top: 3px;">*</span>名&emsp;&emsp;称</label>
                <div class="layui-input-inline">
                    <input name="name" id="name" lay-verify="required" autocomplete="off" class="layui-input" type="text">
                </div>
                <label class="layui-form-label"><span style="color: red;top: 3px;">*</span>组织类型</label>
                <div class="layui-input-inline">
                    <select name="type" id="type_select">
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="shortName"><span style="color: red;top: 3px;">*</span>简&emsp;&emsp;称</label>
                <div class="layui-input-inline">
                    <input name="shortName" id="shortName" lay-verify="required" autocomplete="off" class="layui-input" type="text">
                </div>
                <label class="layui-form-label"><span style="color: red;top: 3px;">*</span>组织级别</label>
                <div class="layui-input-inline">
                    <select name="hierarchy" id="hierarchy_select">
                    </select>
                </div>
            </div>
            <div class="layui-form-item ">
                <label class="layui-form-label">上级组织</label>
                <div class="layui-input-block" style="width:82%;">
                    <input type="text" class="layui-input"  id="parentName" disabled/>
                </div>
                <div class="layui-input-block" style="display: none">
                    <input type="text" class="layui-input" name="parentId" id="parentId"/>
                </div>
            </div>
            <div class="layui-form-item ">
                <div class="layui-inline">
                    <label class="layui-form-label">状&emsp;&emsp;态</label>
                    <div class="layui-input-inline">
                        <select name="state" id="project_state">
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" for="sort"><span style="color: red;top: 3px;">*</span>排&emsp;&emsp;序</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="sort"  name="sort"/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item ">
                <div class="layui-inline">
                    <label class="layui-form-label">编&emsp;&emsp;码</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="orgCode"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">域&emsp;&emsp;名</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input"  name="domainName"/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item ">
                <div class="layui-inline">
                    <label class="layui-form-label">电&emsp;&emsp;话</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input"  oninput="this.value=this.value.replace(/[\u4e00-\u9fa5]/ig,'')" name="phone"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">传&emsp;&emsp;真</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input"  name="fax"/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item ">
                <div class="layui-inline">
                    <label class="layui-form-label">邮&emsp;&emsp;编</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input"  oninput="this.value=this.value.replace(/[\u4e00-\u9fa5]/ig,'')" name="postalCode"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">网&emsp;&emsp;站</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input"  name="webSite"/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item ">
                <div class="layui-inline">
                    <label class="layui-form-label">地&emsp;&emsp;址</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="address"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">GPS坐标</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input input_button" id="gps" name="gps"/>
                        <button class="btn_self layui-btn layui-btn-primary layui-btn-small button_input" onclick="getGps(event)">选择</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<div id='gpsmap' style="display: none;height: 100%;">
    <div id="allmap" style="overflow:hidden;zoom:1;position:relative;width: 100%; height:100%;">
        <div id="map" style="height:100%;-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;"></div>
    </div>
<script>
    var AUflag,flag,node,form,layer;//AUflag1为保存2为更新
    var mk,overlays_one = [],overlays =[],map;
    $(function () {
        layui.use(['form','layer'], function(){
            form =layui.form,
                layer=layui.layer;
        });
        initHierarchy();
        node = window.parent.nodeSelected;
        $("#parentName").val(window.parent.nodeSelected.name);
        $("#parentId").val(window.parent.nodeSelected.id);

    })


    function initHierarchy(){
        //初始化组织级别
        publicAjax(null,'infdictitem/selectInfdictitemByInfdictsortCode',{'code':'OrgLevel'},false,null,function (data){
            if(data.code == 2000){
                var newHierarchy = parseInt(window.parent.nodeSelected.hierarchy)+1;
                var selectStr = '';
                var json= data.data;
                for(var i=0;i<json.length;i++){
                    if(parseInt(json[i].code)==newHierarchy){
                        selectStr = selectStr + "<option selected value='"+json[i].code+"'>"+json[i].name+"</option>";
                    }else{
                        selectStr = selectStr + "<option value='"+json[i].code+"'>"+json[i].name+"</option>";
                    }
                }
                $("select[name='hierarchy']").html('');
                $("select[name='hierarchy']").html(selectStr);

            }
        });
        //初始化组织类型
        publicAjax(null,'infdictitem/selectInfdictitemByInfdictsortCode',{'code':'OrgType'},false,null,function (data){
            if(data.code == 2000){
                var selectStr = '';
                var json= data.data;
                for(var i=0;i<json.length;i++){
                    selectStr = selectStr + "<option value='"+json[i].code+"'>"+json[i].name+"</option>";
                }
                $("select[name='type']").html('');
                $("select[name='type']").html(selectStr);
            }
        });
        //初始化用户状态
        publicAjax(null,'infdictitem/selectInfdictitemByInfdictsortCode',{'code':'UserState'},false,null,function (data){
            if(data.code == 2000){
                var selectStr = '';
                var json= data.data;
                for(var i=0;i<json.length;i++){
                    selectStr = selectStr + "<option value='"+json[i].code+"'>"+json[i].name+"</option>";
                }
                $("select[name='state']").html('');
                $("select[name='state']").html(selectStr);
            }
        });
    }
    //初始化按钮
    function inintOrganizattion(node){
        $('#parentName').val(node.name);
        $('#parentName').attr("readonly","readonly");
        $('#parentId').val(node.id);
    }


    /**
     * 打开地图按钮
     */
    function getGps() {
        var e = document.all ? window.event : arguments[0] ? arguments[0] : event ;
        e.stopPropagation();
        e.preventDefault();
        var index = layer.open({
            type: 1,
            title: '选择GPS',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['750px', '480px'],
            content: $("#gpsmap"),
            btn: ['确定'],
            success: function() {
                $('.layui-layer-btn .layui-layer-btn0').css({
                    'border-color': '#1E9FFF ',
                    'background-color': '#1E9FFF'
                })
                // 百度地图API功能
                map = new BMap.Map('map');
                if(flag==1){
                    var poi = new BMap.Point(117.227737,31.828551);
                }else{
                    if($("#gps").val()){
                        var arr=$("#gps").val().split(',')
                        var poi = new BMap.Point(arr[0],arr[1]);
                    }else{
                        var poi = new BMap.Point(117.227737,31.828551);
                    }
                }
                map.centerAndZoom(poi, 10);
                mk = new BMap.Marker(poi);//创建标注图标
                overlays_one.push(mk);
                map.addOverlay(mk);//将标注添加到地图中
                map.enableScrollWheelZoom();
                var overlaycomplete = function(e) {
                    overlays_one = [];
                    overlays_one.push(e.overlay);
                    overlays.push(e.overlay);
                };
                var styleOptions = {
                    strokeColor: "red", //边线颜色。
                    fillColor: "red", //填充颜色。当参数为空时，圆形将没有填充效果。
                    strokeWeight: 3, //边线的宽度，以像素为单位。
                    strokeOpacity: 0.8, //边线透明度，取值范围0 - 1。
                    fillOpacity: 0.6, //填充的透明度，取值范围0 - 1。
                    strokeStyle: 'solid' //边线的样式，solid或dashed。
                }
                //实例化鼠标绘制工具
                var drawingManager = new BMapLib.DrawingManager(map, {
                    isOpen: false, //是否开启绘制模式
                    enableDrawingTool: true, //是否显示工具栏
                    drawingToolOptions: {
                        anchor: BMAP_ANCHOR_TOP_RIGHT, //位置
                        offset: new BMap.Size(5, 5), //偏离值
                        scale: 0.8, //工具栏缩放比例
                        drawingModes: [BMAP_DRAWING_MARKER]
                    },
                    circleOptions: styleOptions, //圆的样式
                    polylineOptions: styleOptions, //线的样式
                    polygonOptions: styleOptions, //多边形的样式
                    rectangleOptions: styleOptions //矩形的样式
                });
                var timer, count = 0;
                map.addEventListener("click", function(e) {
                    clearAll();
//							count++;
//							timer = window.setTimeout(function() {
//								if(count == 1) {
//									console.log(e.point.lng + '|' + e.point.lat );
//								}
//								window.clearTimeout(timer);
//								count = 0;
//							}, 300)
                });
                drawingManager.addEventListener('overlaycomplete', overlaycomplete);
            },
            yes: function(index, layero) {
                $('.layui-layer-btn .layui-layer-btn0').css({
                    'border-color': '#FFC107',
                    'background-color': '#FFC107'
                })
                $("#gps").val(overlays_one[0].point.lng + ',' + overlays_one[0].point.lat);
                layer.close(index);
            },
            cancel: function(index, layero) {
                $('.layui-layer-btn .layui-layer-btn0').css({
                    'border-color': '#FFC107',
                    'background-color': '#FFC107'
                })
            }
        });
    }

    function clearAll() {
        if (mk) map.removeOverlay(mk);
        if (overlays.length > 1) {
            for (var i = 0; i < overlays.length; i++) {
                if (i != overlays.length - 1) {
                    map.removeOverlay(overlays[i]);
                }
            }
        }
    }

    function submitcreate(url) {
        /*if(!$("input[name='name']").val().replace(/^ +| +$/g,'')) {
            layer.msg('请输入名称！', {
                time: 1000
            });
            return;
        }
        var sort = $.trim($("input[name='sort']").val());
        if((''!=sort) && !(mCheck(sort,'int'))){
            layer.msg('排序不能为空',{time: 1000});
            return ;
        }
        /*var fax=jQuery.trim(jQuery("#addcom input[name='fax']").val());
        if((''!=fax) && !(mCheck(fax,'fax'))){
            layer.msg('传真格式不正确',{time: 1000});
            return ;
        }
        var telephone=jQuery.trim(jQuery("#addcom input[name='phone']").val());
        if((''!=telephone) && !(mCheck(telephone,'compmobile'))){
            layer.msg('公司电话格式不正确',{time: 1000});
            return ;
        }
        // ^[0-9]\\d{5}$
        var postalcode=jQuery.trim(jQuery("#addcom input[name='postalCode']").val());
        if((''!=postalcode)&&  !(mCheck(postalcode,'postalcode'))){
            layer.msg('邮编格式不正确',{time: 1000});
            return ;
        }

        var website=jQuery.trim(jQuery("#addcom input[name='webSite']").val());
        if((''!=website)&&(!(/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/.test(website)))){
            layer.msg('网站格式不正确',{time: 1000});
            return ;
        }*/
        var obj = $(validform().form());
        if(!obj[0]){
            return false;
        }
        var data = $('#formTest').serializeJson();
        var newNode = data;
        newNode.parent = true;
        var urls = url;
        var result;
        publicAjax(null,urls,data,false,null,function(data){
            if(data.code == 2000){
                var index = window.parent.index_i1;
                laysuccess("保存成功！");
                delayLoad(function(){
                    parent.layer.close(index);
                    //window.parent.initTree("#treeDemo");
                })
            }else{
                layself(data.msg);
            }
            result = data;
        })
        return result;
    }

    //编写表单验证函数validform，在验证按钮注册按钮点击事件内调用验证函数对象
    function validform(){
        return $("#formTest").validate({
            rules : {
                name : {
                    required:true,
                    normalizer: function( value ) {
                        return $.trim( value );
                    }
                },
                shortName : {
                    required:true,
                    normalizer: function( value ) {
                        return $.trim( value );
                    }
                },
                sort : {
                    required:true,
                    number:true,
                    normalizer: function( value ) {
                        return $.trim( value );
                    }
                }
            },
            messages : {
                name : {
                    required: "请输入名称！"
                },
                shortname:{
                    required: "请输入简称！"
                },
                sort:{
                    required: "请输入排序！"
                }
            }
        });
    }


</script>

</html>
